ESP32 Based Real Time Corona Case Counter

Novel coronavirus (Covid-19) is declared a pandemic by WHO. Almost all country is suffering and most of them are in a lockdown situation. Hundreds of thousands are infected and thousands are dead and this number is increasing exponentially. Only emergency services like hospitals, electricity, water supply are in operation with possible precautions. People are not allowed to step out of their homes.

Some websites like Worldometers, Corona Virus Esri API show real-time corona cases, the number of recovers, deaths, etc. Based on the data displayed over this website we will show you how to display data and manipulate it according to your requirement. In this tutorial, we display Covid-19 world and SAARC data (total cases, death, and recovery).

Note*: SAARC represents for “South Asian Association for Regional Cooperation” as an inter-governmental organization and its member countries are Afghanistan, Bangladesh, Bhutan, India, the Maldives, Nepal, Pakistan, and Sri Lanka.

world corona real time counterFigure: Author Prototype of ESP32 Based Real-Time Corona Case Counter

Circuit Diagram ESP32 Based Real-Time Corona Case Counter

In the project “ESP32 Based Real-Time Corona Case Counter,” we will build a DIY corona real-time counter for the world and SAARC. It shows different parameters like total no of cases, death, and recovery. This DIY project is simple and required only two components i.e. ESP32 and I2C LCD. For this project an RGB I2C LCD by seeedstudio, the circuit is shown in figure 1. ESP32 is used here to fetch data from the web and display it over RGB LCD. Two pins of LCD, SCL, and SDA are connected to SCL and SDA pin of ESP32 where the power supply is connected to power rails (+5V and GND) as shown in the circuit diagram.

Circuit Diagram of ESP32 Based Real Time Corona Case Counter

Note: The I2C LCD module we had used in this project requires a 5V power supply and ESP32 does not have a 5V supply pin thus we had used an external 5V power supply.

Getting API Ready for Real-Time Corona Case Counter

Getting JSON code for SAARC

Step 1: Go to website “coronavirus-disasterresponse

Step 2: Select the parameter you need like specific country, confirmed, recover, death, etc.

selecting parameter for corona virus

Figure 2: Selecting Parameter for Corona Virus

Note: In this article, we are showing confirmed cases, death, and recovery of SAARC country.

Step 3: Make all the output and input parameters either OFF or False.

selecting input and output parameter for json code

Figure 3: Selecting Input and Output Parameter for JSON Code

Step 4: Click on either “Try it out” or on the link on the right side “Query URL”. There you will get JSON data.

JSON code for Corona case

Figure 4: JSON Code for Corona Case

Step 5: We had manipulated the URL to get data of a specific country. In URL change the country name you want to display the data.

Note: This URL is for the country Nepal.

Step 5: Now we have to phrase the JSON data according to our requirement for that go to the link ArduinoJson Assistant and paste the JSON code in input.

input code for JSON phrasing

Figure 5: Input Code for JSON Phrasing

Step 6: Copy the code from the phrasing program section as per your requirement, here we are displaying total cases, death, and recovery of SAARC.

Phrasing Program for JSON Code

Figure 6: Phrasing Program for JSON Code

Step 7: Do the same process for the new country you wish to display on your display.

Getting code for World Data

Step 1: Go to the website “Worldometers

Step 2: Scroll down and then right-click on the world total case cell, go to inspect element.

inspect element of world caseFigure 7: Inspect Element of World Case

Step 3: Copy the XPath of World Total Case (You can copy XPath either by clicking three-dot (…) or by right-click).

xpath for world case

Figure 8: XPath for World Case

Step 4: Now open the ThingSpeek website and then go to Apps>>ThingHTTP

thinkspeek page

Figure 9: ThingSpeek Page

Step 5: Now click on NewThingHTTP. (Note: For testing, we had created a few HTTP).

dashboard for http

Figure 10: Dashboard for HTTP

Step 6: In Name field, add the name (say World Case); in URL field add the ERL of WorldoMeter “https://www.worldometers.info/coronavirus/”; in Phrasing Field add the XPath of world case that you had copied from worldometer and finally save the data by clicking Save ThingHTTP.

http setup for thingspeak

Figure 11: HTTP Setup for ThingSpeak

Step 7: Note down the API key, you have to use this URL and key in software code.

api key for http code

Figure 12: API Key for HTTP Code

Software Code for ESP32 Based Real-Time Corona Case Counter:

Software code is written in Arduino programming language (C/C++) and compiled using Arduino IDE. You have to edit some code before using it like, URL code, SSID and password, etc.

Note: Before using code you have to update the Arduino JSON library to version 6.15.0.

Leave a Comment